<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class WorkLevel extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->load->model('muser');
   $this->load->library('form_validation');
   $this->load->library('pagination');
 }
 function index(){
	 
 	 $config['base_url'] = base_url().'workLevel/index'; 
	 $config['total_rows'] = $this->muser->num_rows('WorkLevel');
	 
	 $config['per_page'] = 10; // xác định số record ở mỗi trang  
     $config['uri_segment'] = 3; // xác định segment chứa page number  
	 $this->pagination->initialize($config); 
	 $data['result']=$this->muser->getalldata('WorkLevel',$config['per_page'],$this->uri->segment(3));	
	 
	 if ($error=$this->session->userdata('error')) {
	 	$data['error']=$error;
		$this->session->unset_userdata('error'); 
	 }
	 $this->load->view('_header');
     $this->load->view('workLevel/workLevel_view',$data); 
     $this->load->view('_footer');
 }
 function insert()
 {			
		$DT=array(
			'WorkLevel_ID'=>$this->input->post("WorkLevel_ID"),
			'Position'=>$this->input->post("Position"),
			 'StandardBasicSalary'=>$this->input->post("StandardBasicSalary"),
			 'PositionAllowance'=>$this->input->post("PositionAllowance"),
			 'ResponsibilityAllowance'=>$this->input->post("ResponsibilityAllowance"),
			 'HousingAllowance'=>$this->input->post("HousingAllowance")
		);
		
		$data['error']='Insert successful!';
	
		if ($this->check_WorkLevel($DT['WorkLevel_ID']))
			{
				$this->muser->addData('WorkLevel',$DT);
				$data['error']='Edit successful!';
			}else
			{
				$error['error']=$DT['WorkLevel_ID']. ' is existed in a WorkLevel!';
			}
	$this->session->set_userdata($error);
		redirect('workLevel/index');				
 }

 function delete($WorkLevel_ID){
  		$er=$this->muser->delColumn('WorkLevel','WorkLevel_ID',$WorkLevel_ID);
		redirect('workLevel/index'); 
 	}			
	

 function edit1 ()
 {
 	$DT=array(
			'WorkLevel_ID'=>$this->input->post("WorkLevel_ID"),
			'Position'=>$this->input->post("Position"),
			 'StandardBasicSalary'=>$this->input->post("StandardBasicSalary"),
			 'PositionAllowance'=>$this->input->post("PositionAllowance"),
			 'ResponsibilityAllowance'=>$this->input->post("ResponsibilityAllowance"),
			 'HousingAllowance'=>$this->input->post("HousingAllowance")
		);
	$this->muser->updateData('WorkLevel','WorkLevel_ID',$DT['WorkLevel_ID'],$DT);	 	
	redirect('workLevel/index');		
 } 
 function edit($str)
 {	
 	$result=$this->muser->getRdata('WorkLevel','WorkLevel_ID',$str);
	$data['result']=$result;	
 	$this->load->view('_header');
	$this->load->view('workLevel/editWorkLevel_view',$data);	
	$this->load->view('_footer');
 }
 
 function check_WorkLevel($str){
 		return $this->muser->checkData('WorkLevel','WorkLevel_ID',$str);		
 }
}